package page.pc.homePage;


import basicTool.WaitTool;
import basicTool.window.WindowsUtil;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import page.pc.AbstractPCPage;
import page.pc.newListPage.NewListPage;
import page.pc.vendorPage.VendorWeiBoPage;

import java.util.List;

public class PCHomePage extends AbstractPCPage {

    @FindBy(css = "#j-down")
    private WebElement DownLoadButton;
    
    @FindBy(css = "#j-down")
    private WebElement downloadByScanQRButton;

    @FindBy(css = ".banner-footer>li:first-child")
    private WebElement bannerFooterFirstNewsLink;

    @FindBy(css = ".banner-footer>li:nth-child(2)")
    private WebElement bannerFooterSecondNewsLink;

    @FindBy(css = ".banner-footer>li:last-child")
    private WebElement bannerFooterThirdNewsLink;


    @FindBy(css = ".content-container.first-content")
    private WebElement sectionPartTwoArea;

    @FindBy(css = ".item-img.item-img2")
    private WebElement itemAnimationIMG;


    @FindBy(css = ".content-container.second-content")
    private WebElement sectionPartThreeArea;

    //最新动态
    @FindBy(css = ".content-container.second-content>.contetnt li")
    private List<WebElement> latestNewsList;

    @FindBy(css = ".content-container.second-content>.contetnt>.button")
    private WebElement readMoreNewsLink;


    //奖项与荣誉
    @FindBy(css = ".content-container.third-content")
    private WebElement sectionPartFourArea;

    @FindBy(css = ".footer")
    private WebElement footerArea;

    @FindBy(css = ".footer .pull-right.focus-weixin")
    private WebElement followUsByWeChatLink;

    @FindBy(css = ".pull-left.focus-weibo")
    private WebElement followUsByWeiBoLink;


    public PCHomePage(WebDriver driver) {
        super(driver);
        WaitTool.waitFor(driver, WaitTool.DEFAULT_WAIT_4_ELEMENT, DownLoadButton);
    }

    
    public PCHomePage moveToDownloadByScanQRCode() throws Exception{
    	return moveToElement(downloadByScanQRButton);
    }

    public LatestNewsPage clickbannerFooterFirstNewsLink() throws Exception{
        return click(bannerFooterFirstNewsLink, LatestNewsPage.class);
    }

    public LatestNewsPage clickBannerFooterSecondNewsLink() throws Exception{
        return click(bannerFooterSecondNewsLink, LatestNewsPage.class);
    }

    public LatestNewsPage clickBannerFooterThirdNewsLink() throws Exception{
        return click(bannerFooterThirdNewsLink, LatestNewsPage.class);
    }

    /**
     * 将鼠标移动到页面第二部分"为什么要用借贷宝"
     * @return
     * @throws Exception
     */
    public PCHomePage moveToSecondSection() throws Exception {
        return moveToElement(sectionPartTwoArea);
    }

    public PCHomePage moveToItemShowAnimation() throws Exception{
        this.moveToSecondSection();
        return moveToElement(itemAnimationIMG);
    }

    /**
     * 移动至页面第三部分: 最新动态
     * @return
     * @throws Exception
     */
    public PCHomePage moveToThridSection() throws Exception {
        return moveToElement(sectionPartThreeArea);
    }

    public NewListPage readMoreNews() throws Exception{
        this.moveToThridSection();
        return click(readMoreNewsLink, NewListPage.class);
    }


    public PCHomePage moveToFourthSection() throws Exception{
        return moveToElement(sectionPartFourArea);
    }


    public PCHomePage moveToFooterArea() throws Exception{
        return moveToElement(footerArea);
    }

    public PCHomePage followUsByWeChat() throws Exception {
        moveToFooterArea();
        return moveToElement(followUsByWeChatLink);
    }

    public VendorWeiBoPage followUsByWeiBo() throws Exception {
        moveToFooterArea();
        click(followUsByWeiBoLink);
        WindowsUtil.getInstance(driver).switchWindow();
        return new VendorWeiBoPage(driver);
    }

}
